package com.jlstu.designmodedemo.factory;

import com.jlstu.designmodedemo.abstracthandler.AbstractColaHandler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ColaFactory {
    // 定义策略map缓存
    private static Map<String, AbstractColaHandler> strategyMap = new ConcurrentHashMap<>();

    public static AbstractColaHandler getInvokeStrategy(String str) {
        return strategyMap.get(str);
    }

    public static void register(String str, AbstractColaHandler handler) {
        if (null == str || null == handler) {
            throw new UnsupportedOperationException();
        }
        strategyMap.put(str, handler);
    }
}
